import { deleteByPrimaryKeyForProTableAuth, selectByPrimaryKeyForProTableAuth, insertForProTableAuth, updateForProTableAuth, deleteByMapForProTableAuth,updateByMapForProTableAuth, getOneForProTableAuth,getAllForProTableAuth,queryPageForProTableAuth, countForProTableAuth, insertBatchForProTableAuth, deleteBatchForProTableAuth,updateBatchForProTableAuth,getPageProTablesByAuthId,queryPageForProAuthority,queryPageForProTableChild,getSelectedProTableByAuthId } from '@/services/system/api_protableauth';

export default {
    namespace: 'protableauth',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        table: {
        	list: [],
        	pagination: {}
        },
        tableChild: {
        	list: [],
        	pagination: {}
        },
        tableSelect: {
        	list: [],
        }
    },

    effects: {
            *delete_by_primarykey_for_protableauth({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProTableAuth, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProTableAuth',
                    payload: response,
                });
            },
            *select_by_primarykey_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProTableAuth, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(insertForProTableAuth, payload);
                yield put({
                    type: 'insertForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(updateForProTableAuth, payload);
                yield put({
                    type: 'updateForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *delete_by_map_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProTableAuth, payload);
                yield put({
                    type: 'deleteByMapForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_by_map_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProTableAuth, payload);
                yield put({
                    type: 'updateByMapForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_one_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProTableAuth, payload);
                yield put({
                    type: 'getOneForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_all_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProTableAuth, payload);
                yield put({
                    type: 'getAllForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProTableAuth, payload);
                yield put({
                    type: 'queryPageForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *count_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(countForProTableAuth, payload);
                yield put({
                    type: 'countForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_batch_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProTableAuth, payload);
                yield put({
                    type: 'insertBatchForProTableAuth',
                    payload: response,
                });
                
                const responsedata = yield call(queryPageForProAuthority, {});
                yield put({
                	type: 'queryPageForProAuthority',
                	payload: responsedata,
                });
                
                const newPayload = { auth_id: [payload.authids[0].id]};
                const responseTable = yield call(getPageProTablesByAuthId, newPayload);
                yield put({
                    type: 'getPageProTablesByAuthId',
                    payload: responseTable,
                });
                
                if (callback) callback();
            },
            *delete_batch_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProTableAuth, payload);
                yield put({
                    type: 'deleteBatchForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_batch_for_protableauth({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProTableAuth, payload);
                yield put({
                    type: 'updateBatchForProTableAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_page_protables_by_authid({ payload, callback }, { call, put }) {
                const response = yield call(getPageProTablesByAuthId, payload);
                yield put({
                    type: 'getPageProTablesByAuthId',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_proauthority({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProAuthority, payload);
                yield put({
                    type: 'queryPageForProAuthority',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_protablechild({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProTableChild, payload);
                yield put({
                    type: 'queryPageForProTableChild',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_selected_protable_by_authid({ payload, callback }, { call, put }) {
                const response = yield call(getSelectedProTableByAuthId, payload);
                yield put({
                    type: 'getSelectedProTableByAuthId',
                    payload: response,
                });
                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProTableAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getPageProTablesByAuthId(state, action) {
            return {
                ...state,
                table: action.payload,
            };
        },
        queryPageForProAuthority(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProTableChild(state, action) {
            return {
                ...state,
                tableChild: action.payload,
            };
        },
        getSelectedProTableByAuthId(state, action) {
            return {
                ...state,
                tableSelect: action.payload,
            };
        },
    },
};
